package com.cloudptt.wp.ui.more.bt;

import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;

import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class BluetoothDevicePreference extends Preference {

	private Context context;
	private TextView titleTextView;
	private TextView summaryTextView;
	
	private String deviceName;
	private String deviceAddr;
	
	private ImageView mWidgetImageView;
	
	private boolean connectTag = false;
		
	public BluetoothDevicePreference(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}

	public BluetoothDevicePreference(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		// TODO Auto-generated constructor stub
	}

	public BluetoothDevicePreference(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
		this.context = context;
		setWidgetLayoutResource(R.layout.preference_widget_unchecked);
	}
	
	@Override
	protected View onCreateView(ViewGroup parent) {
		// TODO Auto-generated method stub
		Log.d("lq", "onCreateView");
		return super.onCreateView(parent);
	}
	
	@Override
	protected void onBindView(View view) {
		// TODO Auto-generated method stub
		
		Log.d("lq", "onBindView");
		super.onBindView(view);
		
		titleTextView = (TextView) view.findViewById(android.R.id.title);
		titleTextView.setTextColor(context.getColor(android.R.color.black));
		
		summaryTextView = (TextView) view.findViewById(android.R.id.summary);
		summaryTextView.setTextColor(context.getColor(android.R.color.black));
		
		/*mWidgetImageView = (ImageView) view.findViewById(R.id.custom_img);
		Log.d("lq","mWidgetImageView = "+mWidgetImageView);*/
	}
	
	public void onConnected(){
		if(titleTextView != null){
			titleTextView.setTextColor(context.getColor(android.R.color.holo_blue_dark));
		}
		
		if(summaryTextView != null){
			summaryTextView.setTextColor(context.getColor(android.R.color.holo_blue_dark));
		}
		
		setSelectable(true);
	}
	
	public void onDisconnected(){
		if(titleTextView != null){
			titleTextView.setTextColor(context.getColor(android.R.color.black));
		}
		
		if(summaryTextView != null){
			summaryTextView.setTextColor(context.getColor(android.R.color.black));
		}
		
		setSelectable(false);
	}
	
	@Override
	protected void onClick() {
		// TODO Auto-generated method stub
		super.onClick();
		//onConnected();
	}
	
	public void clearSelected(){
		//setWidgetLayoutResource(R.layout.preference_widget_unchecked);
	}
	
	@Override
	public void setSelectable(boolean selectable) {
		// TODO Auto-generated method stub
		super.setSelectable(selectable);
		
			onConnected();
		
		//mWidgetImageView.setImageResource(selectable ? R.drawable.check_32px_2 : R.drawable.checkbox_false);
	}
	
	public void setTag(boolean isConnect){
		connectTag = isConnect;
	}
	
	public boolean getTag(){
		return connectTag;
	}
} 
